package cn.com.cabinet.manager.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cabinet.base.util.DateUtil;
import com.cabinet.web.entity.Coclass;

import cn.com.cabinet.dao.CoclassDao;

@Controller
@RequestMapping("/manager/coclass")
public class CoclassController {
	
	@Autowired
	private CoclassDao coclassDao;
	
	@RequestMapping("/index")
	public String index(ModelMap modelMap){
		System.out.println("colass");
		List<Coclass> coclass = coclassDao.findAll();
		modelMap.addAttribute("coclass", coclass);
		return "/coclass/index";
	}
	
	@RequestMapping("/add")
	public String addCoclass(){
		return "/coclass/add";
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public int delete(Long Id){
		Coclass coclass = coclassDao.findOne(Id);
		coclassDao.delete(coclass);
		return 1;
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public int save(String coclassName){
		Coclass coclass = new Coclass();
		coclass.setClaNo(DateUtil.DateNum());
		coclass.setClaname(coclassName);
		coclassDao.save(coclass);
		return 1;
	}

}
